-- Scoreboard
-- plz do not steal this
-- thnx
-- Scripted by Waffler

if( Scoreboard ) then
	Scoreboard:Remove();
	Scoreboard = nil;
end

surface.CreateFont( "Mailart Rubberstamp", 20, 200, true, false, "ScoreboardFont" );

function CreateScoreboard()
	
	Scoreboard = CreateBPanel( nil, ScrW() * .25 + 150, ScrH() * .25, 300, 450 );
	Scoreboard:CanClose( false );
	Scoreboard.PaintHook = function()
	
		draw.DrawTextOutlined( "PubGamer.org - Half Life 2", "ScoreboardFont", 65, 10, Color( 255, 255, 255, 255 ), nil, nil, 2, Color( 0, 0, 0, 255 ) );
		
	end	
	
	Scoreboard.InnerFrame = CreateBPanel( nil, 5, 20, 290, 400 );
	Scoreboard.InnerFrame:SetParent( Scoreboard );
	Scoreboard.InnerFrame:SetBodyColor( Color( 70, 70, 70, 200 ) );
	Scoreboard.InnerFrame:EnableScrolling( true );
	
	Scoreboard.PlayerRow = { };
	
	local y = 0
	
	for k, v in pairs( player.GetAll() ) do
	
		if( v:IsPlayer() ) then
				
			Scoreboard.PlayerRow[k] = CreateBPanel( nil, 0, -15 + y, Scoreboard.InnerFrame:GetWide(), 75 );
			Scoreboard.PlayerRow[k]:SetParent( Scoreboard.InnerFrame );
			Scoreboard.PlayerRow[k]:SetBodyColor( Color( 50, 50, 50, 200 ) );
						
			Scoreboard.PlayerRow[k].Model = vgui.Create( "SpawnIcon" );
			Scoreboard.PlayerRow[k].Model:SetParent( Scoreboard.PlayerRow[k] );
			Scoreboard.PlayerRow[k].Model:SetModel( v:GetModel() );
			Scoreboard.PlayerRow[k].Model:SetPos( 5, 4 );
			Scoreboard.PlayerRow[k].Model:SetIconSize( 43, 43 );
			
			Scoreboard.PlayerRow[k].NameLabel = Scoreboard.PlayerRow[k]:AddLabel( v:GetRPName(), "NewChatFont", 50, 5, Color( 255, 255, 255, 255 ) );
			Scoreboard.PlayerRow[k].TitleLabel = Scoreboard.PlayerRow[k]:AddLabel( v:GetNWString( "Title" ), "NewChatFont", 50, 20, Color( 255, 255, 255, 255 ) );
			Scoreboard.PlayerRow[k].Title2Label = Scoreboard.PlayerRow[k]:AddLabel( v:GetNWString( "secondtitle" ), "NewChatFont", 50, 35, Color( 255, 255, 255, 255 ) );
			Scoreboard.PlayerRow[k].OOCName = Scoreboard.PlayerRow[k]:AddLabel( v:Nick(), "NewChatFont", 50, 50, Color( 255, 255, 255, 255 ) );
			Scoreboard.PlayerRow[k].Ping = Scoreboard.PlayerRow[k]:AddLabel( v:Ping(), "NewChatFont", Scoreboard.PlayerRow[k]:GetWide() - 40, 5, Color( 255, 255, 255, 255 ) );
			
			Scoreboard.InnerFrame:AddObject( Scoreboard.PlayerRow[k] );
						
			y = y + 76
						
		end

	end	
	
end	

--[[
function CreateScoreboard()

	Scoreboard = CreateBPanel( nil, ScrW() * .25, ScrH() * .25, ScrW() * .5, ScrH() * .5 );
	Scoreboard:SetBodyColor( Color( 50, 50, 50, 100 ) );
	Scoreboard:EnableScrolling( true );
	
	Scoreboard.PlayerRow = { };
	Scoreboard.PlayerIcon = { };
	Scoreboard.PlayerDetails = { };
	
	Scoreboard.TeamRows = { };
	Scoreboard.TeamName = { };

	local x = 0;
	local y = -1;
	
	for k, v in pairs( team.GetAllTeams() ) do
	
		if( team.NumPlayers( k ) > 0 ) then
		
			Scoreboard.PlayerRow[v] = CreateBPanel( nil, x, y - 18, Scoreboard:GetWide(), 20 );
			Scoreboard.PlayerRow[v]:SetParent( Scoreboard );
			Scoreboard.PlayerRow[v]:SetBodyColor( Color( 40, 40, 40, 170 ) );
			
			Scoreboard.TeamName[v] = Scoreboard:AddLabel( team.GetName( k ), "NewChatFont", x + 15, y + 3 );
			
			y = y + 22;
			
			for _, ply in pairs( player.GetAll() ) do
			
				if( ply ) then
				
					if( team.GetName( ply:Team() ) == team.GetName( k ) ) then

						Scoreboard.PlayerDetails[ply] = Scoreboard:AddLabel( ply:GetRPName(), "NewChatFont", x + 76, y + 5 );
						Scoreboard.PlayerDetails[ply] = Scoreboard:AddLabel( ply:Ping(), "NewChatFont", x + Scoreboard:GetWide() - 40, y + 5 );
						Scoreboard.PlayerDetails[ply] = Scoreboard:AddLabel( ply:GetNWString( "title" ) , "NewChatFont", x + 76, y + 19, Color( 200, 200, 200, 255 ) );
						Scoreboard.PlayerDetails[ply] = Scoreboard:AddLabel( ply:GetNWString( "secondtitle" ), "NewChatFont", x + 76, y + 33, Color( 200, 200, 200, 255 ) );
						Scoreboard.PlayerDetails[ply] = Scoreboard:AddLabel( ply:Nick(), "NewChatFont", x + 76, y + 48, Color( 255, 255, 255, 255 ) );
						
						Scoreboard.PlayerIcon[ply] = vgui.Create( "SpawnIcon", Scoreboard );
						Scoreboard.PlayerIcon[ply]:SetPos( x + 6, y + 2 );
						Scoreboard.PlayerIcon[ply]:SetModel( ply:GetModel() );
						
						Scoreboard:AddObject( Scoreboard.PlayerIcon[ply] );
						Scoreboard:AddObject( Scoreboard.PlayerRow[v] );
			
						y = y + 70;
							
					end

				end

			end

		end	

	end	

end--]]

function GM:ScoreboardShow()

	if( not Scoreboard ) then
		CreateScoreboard();
	end
	
	Scoreboard:SetVisible( true );

	gui.EnableScreenClicker( true );

end

function GM:ScoreboardHide()

	if( Scoreboard ) then
		Scoreboard:Remove();
		Scoreboard = nil;
	end	

end	
	